<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="设备驱动," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="1、LCD12864串口驱动程序#include &amp;lt;linux/module.h&amp;gt;
#include &amp;lt;linux/kernel.h&amp;gt;
#include &amp;lt;linux/types.h&amp;gt;
#include &amp;lt;linux/sched.h&amp;gt;
#include &amp;lt;linux/init.h&amp;gt;
#include &amp;lt;linux/fs.h&amp;gt;">
<meta property="og:type" content="article">
<meta property="og:title" content="LCD12864串口驱动udev">
<meta property="og:url" content="http://ideask.cf/2017/01/22/12864-udev-char-device/index.html">
<meta property="og:site_name" content="Jason Lin">
<meta property="og:description" content="1、LCD12864串口驱动程序#include &amp;lt;linux/module.h&amp;gt;
#include &amp;lt;linux/kernel.h&amp;gt;
#include &amp;lt;linux/types.h&amp;gt;
#include &amp;lt;linux/sched.h&amp;gt;
#include &amp;lt;linux/init.h&amp;gt;
#include &amp;lt;linux/fs.h&amp;gt;">
<meta property="og:updated_time" content="2017-01-22T13:55:39.387Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="LCD12864串口驱动udev">
<meta name="twitter:description" content="1、LCD12864串口驱动程序#include &amp;lt;linux/module.h&amp;gt;
#include &amp;lt;linux/kernel.h&amp;gt;
#include &amp;lt;linux/types.h&amp;gt;
#include &amp;lt;linux/sched.h&amp;gt;
#include &amp;lt;linux/init.h&amp;gt;
#include &amp;lt;linux/fs.h&amp;gt;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://ideask.cf/2017/01/22/12864-udev-char-device/"/>





  <title> LCD12864串口驱动udev | Jason Lin </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Jason Lin</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle">Jason's Blog</p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://ideask.cf/2017/01/22/12864-udev-char-device/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Jason Lin">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Jason Lin">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Jason Lin" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                LCD12864串口驱动udev
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-01-22T20:08:48+08:00">
                2017-01-22
              </time>
			  </span>
			
			<span>
    
			<span>更新于</span>
			<time>
			2017-01-22
			20:08:48
			</time>
			</span>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/设备驱动/" itemprop="url" rel="index">
                    <span itemprop="name">设备驱动</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/01/22/12864-udev-char-device/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2017/01/22/12864-udev-char-device/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1、LCD12864串口驱动程序"><a href="#1、LCD12864串口驱动程序" class="headerlink" title="1、LCD12864串口驱动程序"></a>1、LCD12864串口驱动程序</h2><pre><code class="bash"><span class="comment">#include &lt;linux/module.h&gt;</span>
<span class="comment">#include &lt;linux/kernel.h&gt;</span>
<span class="comment">#include &lt;linux/types.h&gt;</span>
<span class="comment">#include &lt;linux/sched.h&gt;</span>
<span class="comment">#include &lt;linux/init.h&gt;</span>
<span class="comment">#include &lt;linux/fs.h&gt;</span>
<span class="comment">#include &lt;linux/ioctl.h&gt;</span>
<span class="comment">#include &lt;linux/delay.h&gt;</span>
<span class="comment">#include &lt;linux/bcd.h&gt;</span>
<span class="comment">#include &lt;linux/capability.h&gt;</span>
<span class="comment">#include &lt;linux/rtc.h&gt;</span>
<span class="comment">#include &lt;linux/cdev.h&gt;</span>
<span class="comment">#include &lt;linux/device.h&gt;</span>
<span class="comment">#include &lt;linux/gpio.h&gt;</span>
<span class="comment">#include &lt;linux/version.h&gt;</span>

<span class="comment">#include &lt;../arch/arm/mach-mx28/mx28_pins.h&gt;</span>

<span class="comment">#define DEVICE_NAME "LCD12864"</span>

<span class="comment">#define LCD_SID 57</span>
<span class="comment">#define LCD_CS 39</span>
<span class="comment">#define LCD_CLK 56</span>

<span class="comment">#define LCD_IOC_MAGIC 'L'</span>
<span class="comment">#define LCD_CMD _IO(LCD_IOC_MAGIC,0)</span>
<span class="comment">#define LCD_LINE _IO(LCD_IOC_MAGIC,1)</span>
<span class="comment">#define LCD_ROW _IO(LCD_IOC_MAGIC,2)</span>
<span class="comment">#define LCD_DATA _IO(LCD_IOC_MAGIC,3)</span>

<span class="comment">#define LCD_IOCTL_MAXNR 4</span>


<span class="comment">#define LCD_SID_H gpio_direction_output(LCD_SID,1);</span>
<span class="comment">#define LCD_SID_L gpio_direction_output(LCD_SID,0);</span>
<span class="comment">#define LCD_CS_H gpio_direction_output(LCD_CS,1);</span>
<span class="comment">#define LCD_CS_L gpio_direction_output(LCD_CS,0);</span>
<span class="comment">#define LCD_CLK_H gpio_direction_output(LCD_CLK,1);</span>
<span class="comment">#define LCD_CLK_L gpio_direction_output(LCD_CLK,0);</span>

static int major,minor;
struct cdev *lcd;
static dev_t devno;
static struct class *lcd_class;
static int lcd_open(struct inode *inode,struct file *filp);
static int lcd_release(struct inode *inode,struct file *filp);
static int lcd_ioctl(struct inode *inode,struct file *flip,unsigned int <span class="built_in">command</span>,unsigned long arg);
static int lcd_init(void);
static void lcd_exit(void);

struct file_operations lcd_fops ={
    .owner = THIS_MODULE,
    .open =lcd_open,
    .release = lcd_release,
<span class="comment">#if LINUX_VERSION_CODE &gt;= KERNEL_VERSION(2,6,36)</span>
    .unlocked_ioctl = lcd_ioctl,
<span class="comment">#else</span>
    .ioctl = lcd_ioctl
<span class="comment">#endif</span>
};

static void lcd_sendbyte(unsigned char byte)
{
    unsigned int i=0;
    <span class="keyword">for</span>(i=0;i&lt;8;i++)
    {
        LCD_CLK_L;
        udelay(1);
        <span class="keyword">if</span>(byte &amp; 0x80)
        {LCD_SID_H;}
        <span class="keyword">else</span>
        {LCD_SID_L;}
        LCD_CLK_H;
        udelay(1);
        LCD_CLK_L;
        udelay(1);
        byte = byte &lt;&lt; 1;
    }
}

static void lcd12864_write_cmd(unsigned char cmd)
{
    LCD_CS_H;
    lcd_sendbyte(0xf8);
    lcd_sendbyte(0xf0 &amp; cmd);
    lcd_sendbyte(0xf0 &amp; (cmd &lt;&lt; 4));
    LCD_CS_L;
    mdelay(10);
}

static void lcd12864_write_dat(unsigned char dat)
{

    LCD_CS_H;
    lcd_sendbyte(0xfa);
    lcd_sendbyte(0xf0 &amp; dat);
    lcd_sendbyte(0xf0 &amp; (dat &lt;&lt; 4));
    LCD_CS_L;
    mdelay(10);
}
static void lcd12864_init(void)
{
    lcd12864_write_cmd(0x30);
    lcd12864_write_cmd(0x02);
    lcd12864_write_cmd(0x06);
    lcd12864_write_cmd(0x0c);
    lcd12864_write_cmd(0x01);
    lcd12864_write_cmd(0x80);

}
static void lcd12864_clean(void)
{
    lcd12864_write_cmd(0x01);
}
static void lcd_string(unsigned char x,unsigned char y,unsigned char *String)
{
    <span class="keyword">if</span>((x &lt; 8)&amp;&amp;(y &lt; 4))
    {
        switch(y)
        {
            <span class="keyword">case</span> 0:
                lcd12864_write_cmd(0x80|0x00|x);
                <span class="built_in">break</span>;
            <span class="keyword">case</span> 1:
                lcd12864_write_cmd(0x80|0x10|x);
                <span class="built_in">break</span>;
            <span class="keyword">case</span> 2:
                lcd12864_write_cmd(0x80|0x08|x);
                <span class="built_in">break</span>;
            <span class="keyword">case</span> 3:
                lcd12864_write_cmd(0x80|0x18|x);
                <span class="built_in">break</span>;
        }
        <span class="keyword">while</span>(*String !=<span class="string">'\0'</span>)
        {
            lcd12864_write_dat(*String);
            mdelay(50);
            String++;
        }
    }

}    
static int lcd_open(struct inode *inode,struct file *file)
{
    try_module_get(THIS_MODULE);
    lcd12864_init();//init lcd12864 cmd 
    //init lcd12864 background
    lcd_string(0,0,<span class="string">"Linux Chardev"</span>);
    lcd_string(0,1,<span class="string">"LCD12864 Device"</span>);
    lcd_string(0,2,<span class="string">"Initialization"</span>);
    lcd_string(0,3,<span class="string">"Author:Jason"</span>);
    <span class="built_in">return</span> 0;
}
static int lcd_release(struct inode *inode,struct file *file)
{
    module_put(THIS_MODULE);
    lcd12864_clean();//close lcd12864 background
    lcd_string(0,0,<span class="string">"LCD12864 Device"</span>);
    lcd_string(0,1,<span class="string">"Already"</span>);
    lcd_string(0,2,<span class="string">"Closed"</span>);
    <span class="built_in">return</span> 0;
}


<span class="comment">#if LINUX_VERSION_CODE &gt;= KERNEL_VERSION(2,6,36)</span>
int lcd_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
<span class="comment">#else</span>
static int lcd_ioctl(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
<span class="comment">#endif</span>
{
    <span class="keyword">if</span>(_IOC_TYPE(cmd) != LCD_IOC_MAGIC)
    {
        <span class="built_in">return</span> -ENOTTY;
    }
    <span class="keyword">if</span>(_IOC_NR(cmd) &gt; LCD_IOCTL_MAXNR)
    {
        <span class="built_in">return</span> -ENOTTY;
    }

    switch(cmd)
    {
        <span class="keyword">case</span> LCD_LINE:  //待开发
                <span class="built_in">break</span>;
        <span class="keyword">case</span> LCD_ROW:   //待开发
                <span class="built_in">break</span>;
        <span class="keyword">case</span> LCD_CMD:   //待开发
                <span class="built_in">break</span>;
        <span class="keyword">case</span> LCD_DATA:  //待开发
                <span class="built_in">break</span>;
    }
    <span class="built_in">return</span> 0;


}
static int __init lcd_init(void)
{
    int ret=0;

    gpio_free(LCD_SID);
    gpio_free(LCD_CS);
    gpio_free(LCD_CLK);
    ret += gpio_request(LCD_SID,<span class="string">"SID"</span>);
    ret += gpio_request(LCD_CS,<span class="string">"CS"</span>);
    ret += gpio_request(LCD_CLK,<span class="string">"CLK"</span>);
    <span class="keyword">if</span>(ret)
    {
        printk(<span class="string">"request gpio failed "</span>);
        <span class="built_in">return</span> -1;
    }
    ret = 0;
    ret = alloc_chrdev_region(&amp;devno,minor,1,<span class="string">"LCD12864"</span>);
    major = MAJOR(devno);
    <span class="keyword">if</span>(ret &lt; 0)
    {
        printk(KERN_ERR<span class="string">"cannot get major %d\n"</span>,major);
        <span class="built_in">return</span> -1;
    }
    lcd = cdev_alloc();
    <span class="keyword">if</span>(lcd !=NULL)
    {
        cdev_init(lcd,&amp;lcd_fops);
        lcd-&gt;owner = THIS_MODULE;
        <span class="keyword">if</span>(cdev_add(lcd,devno,1) != 0)
        {
            printk(KERN_ERR<span class="string">"add cdev error! \n"</span>);
            goto error;
        }
    }    
    <span class="keyword">else</span>
    {
        printk(KERN_ERR<span class="string">"cdev_alloc error! \n"</span>);
        <span class="built_in">return</span> -1;
    }

    lcd_class = class_create(THIS_MODULE,<span class="string">"lcd_class"</span>);
    <span class="keyword">if</span>(IS_ERR(lcd_class))
    {
        printk(KERN_INFO<span class="string">"create class error!\n"</span>);
        <span class="built_in">return</span> -1;
    }
    device_create(lcd_class,NULL,devno,NULL,<span class="string">"lcd12864"</span>);
    <span class="built_in">return</span> 0;
error:
    unregister_chrdev_region(devno,1);
    <span class="built_in">return</span> ret;

}
static void __exit lcd_exit(void)
{
    cdev_del(lcd);
    unregister_chrdev_region(devno,1);
    device_destroy(lcd_class,devno);
    class_destroy(lcd_class);
}

module_init(lcd_init);
module_exit(lcd_exit);

MODULE_LICENSE(<span class="string">"GPL"</span>);
MODULE_AUTHOR(<span class="string">"ideask,ideask@ideask.cf"</span>);
</code></pre>
<h2 id="2、Makefile"><a href="#2、Makefile" class="headerlink" title="2、Makefile"></a>2、Makefile</h2><pre><code class="bash">CC = arm-fsl-linux-gnueabi-gcc

ifneq ($(KERNELRELEASE),)
obj-m := lcd.o

PWD :=$(shell <span class="built_in">pwd</span>)
KVER :=$(shell uname -r)
KDIR :=/root/linux-2.6.35.3

all:
    $(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
    rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
</code></pre>
<h2 id="3、测试程序"><a href="#3、测试程序" class="headerlink" title="3、测试程序"></a>3、测试程序</h2><pre><code class="bash"><span class="comment">#include &lt;stdio.h&gt;</span>
<span class="comment">#include &lt;stdlib.h&gt;</span>
<span class="comment">#include &lt;unistd.h&gt;</span>
<span class="comment">#include &lt;sys/ioctl.h&gt;</span>
<span class="comment">#include &lt;errno.h&gt;</span>
<span class="comment">#include &lt;fcntl.h&gt;</span>


<span class="comment">#define DEV_NAME "/dev/lcd12864"</span>

int main(int argc, char *argv[])
{
    int i;
    int fd = 0;
    fd = open(DEV_NAME,O_RDONLY);
    <span class="keyword">if</span>(fd &lt; 0)
    {
        perror(<span class="string">"Open "</span>DEV_NAME<span class="string">"Failed!\n"</span>);
        <span class="built_in">return</span> -1;
    }
    //close(fd);
    <span class="keyword">while</span>(1);
    <span class="built_in">return</span> 0;
}
</code></pre>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>如果文章对您有用请随意打赏，谢谢支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/images/w.png" alt="Jason Lin WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/images/z.jpg" alt="Jason Lin Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/设备驱动/" rel="tag"># 设备驱动</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/01/22/ioctl-led-udev-char-device/" rel="next" title="ioctl方式操作LED udev驱动模板">
                <i class="fa fa-chevron-left"></i> ioctl方式操作LED udev驱动模板
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/23/vim-note/" rel="prev" title="vim笔记">
                vim笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2017/01/22/12864-udev-char-device/"
     data-title="LCD12864串口驱动udev"
     data-content=""
     data-url="http://ideask.cf/2017/01/22/12864-udev-char-device/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2017/01/22/12864-udev-char-device/"
           data-title="LCD12864串口驱动udev" data-url="http://ideask.cf/2017/01/22/12864-udev-char-device/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Jason Lin" />
          <p class="site-author-name" itemprop="name">Jason Lin</p>
          <p class="site-description motion-element" itemprop="description">embedded system engineer</p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/ideask" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/ideask" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/ideask" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://douban.com/people/ideask" target="_blank" title="豆瓣">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  豆瓣
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/ideask" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jyu.edu.cn/" title="嘉应大学" target="_blank">嘉应大学</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、LCD12864串口驱动程序"><span class="nav-number">1.</span> <span class="nav-text">1、LCD12864串口驱动程序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、Makefile"><span class="nav-number">2.</span> <span class="nav-text">2、Makefile</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、测试程序"><span class="nav-number">3.</span> <span class="nav-text">3、测试程序</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jason Lin</span>
</div>



        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"ideask"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  












  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  
  

  


</body>
</html>
